//
//  JiguangSetupConfig.m
//  Pods-UStarter_Example
//
//  Created by Mark on 2021/1/7.
//

#import "JiguangSetupConfig.h"
#import <JPush/JPUSHService.h>

@interface JiguangSetupConfig()

@property(nonatomic,strong) NSString * appKey;
@property(nonatomic,strong) NSDictionary * launchOpts;
@property(nonatomic,assign) BOOL isProduction ;
@property(nonatomic,strong,nullable) NSString * advertisingId;
@property(nonatomic,strong) NSString * channel;

@end

@implementation JiguangSetupConfig

- (instancetype) initWithAppKey:(NSString*)appKey
                     launchOpts:(NSDictionary*)launchOpts
                   isProduction:(BOOL)isProduction
                  advertisingId:(NSString*)advertisingId
                        channel:(NSString*)channel{
    self = [super init];
    if (self) {
        self.appKey = appKey;
        self.launchOpts = launchOpts;
        self.isProduction = isProduction;
        self.advertisingId = advertisingId;
        self.channel=channel ;
    }
    return self;
}


+ (void) setup:(JiguangSetupConfig*)config  delegate:(nonnull id)delegate;{
    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
    
    entity.types = JPAuthorizationOptionAlert
                    |JPAuthorizationOptionBadge
                    |JPAuthorizationOptionSound
                    |JPAuthorizationOptionProvidesAppNotificationSettings;
    
    [JPUSHService registerForRemoteNotificationConfig:entity delegate:delegate];
    
    [JPUSHService setupWithOption:config.launchOpts
                           appKey:config.appKey
                          channel:config.channel
                 apsForProduction:config.isProduction
            advertisingIdentifier:config.advertisingId];
}

@end
